import os
import glob
def renameFiles(dir):
    renameOneDigits(dir)
    files=glob.glob(dir+"/*")
    files.sort()
    id=1
    for file in files:
        basename, extension = os.path.splitext(file)
        mangaNumber=os.path.basename(os.path.dirname(file))
        newName ="c%s-p%02d%s" %(mangaNumber,id,extension)
        id=id+1
        os.rename(file, os.path.dirname(file)+"/"+newName)
def renameOneDigits(dir):
    files=glob.glob(dir+"/*")
    for file in files:
        basename,ext= os.path.splitext(file)
        name=os.path.basename(basename)
        id=int(name)
        newname="%02d%s" %(id,ext)
        os.rename(file, dir+"/"+newname)
            
dir="/home/loai/Desktop /547"
renameFiles(dir)